//
//  ClubForumShareView.swift
//  77Club
//
//  Created by Apple on 2025/1/6.
//

import UIKit

class ClubForumShareView: UIView, RaeAnimationProtocol, RaeAnimationDelegate {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth, height: 220.0.Scale)
    }
    
    func animationContainerViewStyle() -> RaeAnimationViewStyle {
        .bottom
    }
    
    private let cancelButton = c_make_ex(UIButton.self)
        .corner(8.0.Scale).bgColor(.white).text("取消")
        .font(15.font_semiBold).color("#2E3033").end()
    private var shareView = ClubMoreShareView()
    
    var copyShareBlock: ((_ type: Int) -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = "#E8E9EB".toColor
        rae.corner(12.0.Scale, corners: [.layerMinXMinYCorner,.layerMaxXMinYCorner])
        
        subviews{
            shareView
            cancelButton
        }
        
        shareView.top(20.0.Scale).leading(16.0.Scale).trailing(16.0.Scale).height(103.0.Scale)
        cancelButton.leading(16.0.Scale).trailing(16.0.Scale).height(45.0.Scale)
        cancelButton.Top == shareView.Bottom + 9.0.Scale
        
        shareView.copyShareBlock = { type in
            self.entryAnimate.animation(dismiss: self){
                self.copyShareBlock?(type)
            }
        }
        cancelButton.addTarget(self, action: #selector(clickCancelButton), for: .touchUpInside)
    }
    
    @objc private func clickCancelButton(){
        entryAnimate.animation(dismiss: self)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class ClubForumShareDelView: UIView, RaeAnimationProtocol, RaeAnimationDelegate {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth, height: 150.0.Scale)
    }
    
    func animationContainerViewStyle() -> RaeAnimationViewStyle {
        .bottom
    }
    
    private let bgView = c_make_ex(UIView.self)
        .corner(8.0.Scale).bgColor(.white).end()
    private let iconImageView = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).image("Home_more_del").end()
    private let titleLabel = c_make_ex(UILabel.self)
        .font(15.font_medium).text("删除此帖子").color("#B21212").end()
    private let cancelButton = c_make_ex(UIButton.self)
        .corner(8.0.Scale).bgColor(.white).text("取消")
        .font(15.font_semiBold).color("#2E3033").end()

    var delBlock: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = "#E8E9EB".toColor
        rae.corner(12.0.Scale, corners: [.layerMinXMinYCorner,.layerMaxXMinYCorner])
        
        subviews{
            bgView.subviews{
                iconImageView
                titleLabel
            }
            cancelButton
        }
        
        bgView.top(20.0.Scale).leading(16.0.Scale).trailing(16.0.Scale).height(60.0.Scale)
        iconImageView.leading(20.0.Scale).size(20.0.Scale).centerVertically()
        titleLabel.leading(52.0.Scale).centerVertically()
        cancelButton.leading(16.0.Scale).trailing(16.0.Scale).height(45.0.Scale)
        cancelButton.Top == bgView.Bottom + 9.0.Scale
        
        let delTap = UITapGestureRecognizer(target: self, action: #selector(clickDelButton))
        bgView.isUserInteractionEnabled = true
        bgView.addGestureRecognizer(delTap)

        cancelButton.addTarget(self, action: #selector(clickCancelButton), for: .touchUpInside)
    }
    
    @objc private func clickCancelButton(){
        entryAnimate.animation(dismiss: self)
    }
    
    @objc private func clickDelButton(){
        entryAnimate.animation(dismiss: self){
            self.delBlock?()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
